Context Free Grammar

Definition

Parse tree

Chomsky Norm Form

A CFG is in Chomsky Norm Form (CNF) if every of its rules is of three forms

  1. Se
  2. ABC, B,CV/Σ/{S}
  3. Aa, aΣ

PDA

Push-down automata: A PDA is 6-tuple P=(K,Σ,Γ,Δ,s,F)

A language is context-free if and only if it is accpeted by some PDA.

CFGPDA

Given G=(V,Σ,S,R), Construct P=(K,Σ,T,Δ,s,F)

  • K={s,f}
  • F=f
  • T=V
  • Δ=
    • ((s,e,e),(f,S))
    • ((f,e,A),(f,u)), for each (A,u)R
    • ((f,a,a),(f,e)), for each aΣ

Closure property

Provement of Closure property

  • L1L2: SS1|S2
  • L1L2: SS1S2
  • L: SSS|e
  • LR
    • transform to CFG
    • ABC: ACB

Pumping Theorem for CFL

Let L be a context-free language. There exists an integer p>0 such that any wL with |w|p can divided into five pieces w=uvxyz satisfying:

  1. uvixyizL for i0
  2. |v|+|y|>0
  3. |vxy|p
Pumping Theorem for CFL 的技巧

使用类似 滑动窗口 的方法,设置窗口大小为 p,在枚举的字符串中滑动,并穷举所有的情况。